package net.sk.china.front.service.impl.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.sk.china.common.model.system.SystemCity;
import net.sk.china.front.dao.system.SystemCityDao;
import net.sk.china.front.service.system.SystemCityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * SystemCityServiceImpl 接口实现
 * +----------------------------------------------------------------------
 * | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2018-2024 聊来All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * +----------------------------------------------------------------------
 * | @Author: 聊来 <18970881148@qq.com>
 * +----------------------------------------------------------------------
 * | DateTime: 2024/6/13 21:16
 * +----------------------------------------------------------------------
 */

@Service
public class SystemCityServiceImpl extends ServiceImpl<SystemCityDao, SystemCity> implements SystemCityService {

    @Resource
    private SystemCityDao dao;

    /**
     * 根据城市名称获取城市详细数据
     * @param cityName 城市名称
     * @return {@code SystemCity}
     */
    @Override
    public SystemCity getCityByCityName(String cityName) {
        LambdaQueryWrapper<SystemCity> query = new LambdaQueryWrapper<>();
        query.eq(SystemCity::getName,cityName).eq(SystemCity::getIsShow,1);
        query.last("limit 1");

        return dao.selectOne(query);
    }

    /**
     * 获取城市
     * @param cityId 城市id
     * @return {@code SystemCity}
     */
    @Override
    public SystemCity getCityByCityId(Integer cityId) {
        LambdaQueryWrapper<SystemCity> query = new LambdaQueryWrapper<>();
        query.eq(SystemCity::getCityId, cityId).eq(SystemCity::getIsShow, 1);
        query.last("limit 1");

        return dao.selectOne(query);
    }
}
